﻿#include "mainwindow.h"
#include "transdialog.h"

#include <QDebug>
#include <QFileDialog>

#include "./ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->menubar->hide();
}

MainWindow::~MainWindow()
{
    delete ui;
}

/**
 * @brief   导入并显示文件
 */
void MainWindow::on_act_Import_triggered()
{
    auto fileName = QFileDialog::getOpenFileName(this, tr("打开文本文件"), "", tr("Text files (*.*)"));
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QByteArray str = file.readAll();
    text = QString(str);
    ui->textEdit->clear();
    ui->textEdit->append(str);
}

/**
 * @brief   打开翻译对话框
 */
void MainWindow::on_act_Trans_triggered()
{
    TransDialog dlg(this);
    dlg.setText(text);    // 传入文本
    dlg.exec();
}

